package com.groovy.base

class GroovyMethod {

    int x

    static int y = 100

    public static int getY() {
        int ly = 200
        println(ly)
        return y
    }

    int getX() {
        return x
    }

    void setX(int x) {
        this.x = x
    }

    static def DisplayName() {
        println("This is how methods work in groovy");
        println("This is an example of a simple method");
    }

    static void main(String[] args) {
        DisplayName();
        sum(10, 5);
        sum1(6)
        println(sum2(100))

        GroovyMethod method = new GroovyMethod()
        method.setX(10)
        println(method.getX())

        println(getY())

    }


    static void sum(int a, int b) {
        int c = a + b;
        println(c);
    }

// 默认参数方法
    static void sum1(int a, int b = 5) {
        int c = a + b;
        println(c);
    }

// 带有返回值的方法
    static int sum2(int a, int b = 5) {
        int c = a + b;
        return c;
    }
}
